<?php

namespace Budget\BudgetBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Doctrine\ORM\EntityRepository;
use Budget\BudgetBundle\Entity\Family;
use Budget\BudgetBundle\Entity\Expense;

class ExpensesType extends AbstractType
{
    
    protected $userFamily;
    
    public function __construct(Family $userFamily)
    {
        $this->userFamily = $userFamily;
    }
    
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('expenses', 'collection', array(
            'type'         => new ExpenseType($this->userFamily),
            'allow_add'    => true,
            'by_reference' => false,
            'allow_delete' => true
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'expenses';
    }
    
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Budget\BudgetBundle\Entity\Expenses',
        ));
    }

}
